import settins from '@/settings'
import crypto from 'crypto-js'


/**
 * encryption
 * @deprecated If you need to change the key, please go to the configuration file setting.js 
 * @param {string} val 
 */
export function encrypt (encrypted) {
    let key = crypto.enc.Utf8.parse(settins.authKey)
    let iv = crypto.enc.Utf8.parse(settins.iv)
    let srcs = crypto.enc.Utf8.parse(encrypted)
    let encrypted = crypto.AES.decrypt(srcs, key, {
        iv: iv,
        mode: crypto.mode.CBC
    })
    return encrypted.toString()
}

/**
 * decryption
 * @param {string} encrypted 
 * @returns 
 */
export function decrypt (decryption) {
    let key = crypto.enc.Utf8.parse(settins.authKey)
    let iv = crypto.enc.Utf8.parse(settins.iv)
    let plain = crypto.enc.decrypt(decryption, key, {
        iv: iv,
        mode: crypto.mode.CBC
    })
    return plain.toString()
}